/*TCSS 360 ConferenceGuru
 * 
 * Author: Tyler Simrell
 * 
 * This class is the role of the author and contains 
 * the necessary methods for getting the name of the author,
 * getting the manuscript files, and returning a list of papers.
 */
package model;

import java.io.Serializable;
import java.util.List;

public class Author implements Serializable
{

	private static final long serialVersionUID = 2458793509351907630L;
	private List<ConferencePaper> myPapers;
	final private String name;
	
	public Author(List<ConferencePaper> the_papers, String the_name)
	{
		myPapers = the_papers;
		name = the_name;
	}
	
	//This method adds a paper to the list of papers that the author wrote/has.
	public void addPaper(ConferencePaper the_paper)
	{
		myPapers.add(the_paper);
	}
	
	//This method removes a paper from the papers written/held by the author.
	public boolean removePaper(String the_title)
	{
		ConferencePaper found = null;
		for(ConferencePaper temp: myPapers)
		{
			if(temp.getTitle().equals(the_title))
			{
				found = temp;
			}
		}
		if(!found.equals(null))
		{
			myPapers.remove(found);
			return true;
		}
		else
		{
			return false;
		}
	}
	
	//This method returns the name of the author.
	public String getName()
	{
		return name;
	}
	
	//Gets a list of reviews from the ConferencePaper class and returns it.
	public List<Review> getReviews(String the_paper_title)
	{
		List<Review> reviews = null;
		for(ConferencePaper tempPaper: myPapers)
		{
			if(the_paper_title.equals(tempPaper.getTitle()))
			{
				reviews = tempPaper.getReviews();
			}
		}
		return reviews;
	}
	//This method gets the text of the manuscript and returns it.
	public String getManuscriptFile(String the_paper_title)
	{
		String manuscriptFile = null;
		for(ConferencePaper tempPaper: myPapers)
		{
			if(the_paper_title.equals(tempPaper.getTitle()))
			{
				manuscriptFile = tempPaper.getManuscriptFile();
			}
		}
		
		return manuscriptFile;
	}
	
	//This method returns the list of papers attached to this author.
	public List<ConferencePaper> getPapers()
	{
		return myPapers;
	}
	
	//This method sets the manuscript text with that of a string that is sent in.
	public void replaceManuscriptFile(String manuscriptFile, String the_paper_title)
	{
		for(ConferencePaper tempPaper: myPapers)
		{
			if(the_paper_title.equals(tempPaper.getTitle()))
			{
				tempPaper.setManuscriptFile(manuscriptFile);
			}
		}
	}
}
